package org.huang.sample15.controller

import org.huang.sample15.bo.Dept
import org.huang.sample15.dao.DeptAnnoMapper
import org.huang.sample15.dao.DeptXmlMapper
import spock.lang.*
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import static org.mockito.Mockito.*

class DeptControllerTest_G extends Specification {

    def deptXmlMapper = Mock(DeptXmlMapper)
    def deptAnnoMapper = Mock(DeptAnnoMapper)
    def deptController = new DeptController(deptAnnoMapper: deptAnnoMapper, deptXmlMapper: deptXmlMapper)

    @Unroll
    def "test index"() {
        given:
        deptXmlMapper.selectAll() >> [new Dept(id: id, name: 'haha', code: 'no1')]

        when:
        def result = deptController.index()

        then:
        with(result) {
            it[0].id == rsId
            it[0].name == 'haha'
        }
        where:
        id | rsId
        1  | 1
        2  | 2
    }

    def "test index2"() {
        given:
        deptAnnoMapper.findAll() >> [new Dept()]

        when:
        List<Dept> result = deptController.index2()

        then:
        result == [new Dept()]
    }
}
